package com.example.dellpc.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.Toast;

import java.security.acl.Group;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 刘智强 on 2016/8/15.
 */
public class MyExpandableListViewActivity extends Activity {
    private ExpandableListView expandableListView1,expandableListView2;
    private MyExpandableListViewAdapter myExpandableListViewAdapter;
    private List<String> group;
    private List<List<String>> item;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.expandablelistviewactivity);
        initView();
    }

    public void initView() {
        initDatas();
        expandableListView1= (ExpandableListView) findViewById(R.id.expanded_listview1);
        expandableListView2= (ExpandableListView) findViewById(R.id.expanded_listview2);
        myExpandableListViewAdapter = new MyExpandableListViewAdapter(getApplicationContext(), item, group);
        expandableListView1.setAdapter(myExpandableListViewAdapter);
        expandableListView2.setAdapter(myExpandableListViewAdapter);
//        expandableListView.setGroupIndicator(ContextCompat.getDrawable(this,R.mipmap.ic_launcher));

        expandableListView1.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                v=parent.getSelectedView();
                Toast.makeText(getApplicationContext(), item.get(groupPosition).get(childPosition), Toast.LENGTH_LONG).show();
                return true;
            }
        });
        expandableListView2.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {

                Toast.makeText(getApplicationContext(),group.get(groupPosition),Toast.LENGTH_LONG).show();
                return true;
            }
        });
    }

    public void initDatas() {

        group = new ArrayList<>();
        item=new ArrayList<>();
        group.add("A组");
        group.add("B组");
        group.add("C组");
        group.add("D组");


        List<String> A = new ArrayList<>();
        A.add("a");
        A.add("ai");
        A.add("ao");
        A.add("an");
        A.add("ang");
        List<String> B = new ArrayList<>();
        B.add("b");
        B.add("bi");
        B.add("bo");
        B.add("ba");
        B.add("bang");
        List<String> C = new ArrayList<>();
        C.add("c");
        C.add("ci");
        C.add("co");
        C.add("ca");
        C.add("cang");
        List<String> D = new ArrayList<>();
        D.add("d");
        D.add("di");
        D.add("do");
        D.add("da");
        D.add("dang");
        item.add(A);
        item.add(B);
        item.add(C);
        item.add(D);


    }
}
